package com.ruoyi.system.service.impl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CoTestCompany;
import com.ruoyi.system.service.ICoTestCompanyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司管理Controller
 * 
 * @author 冬木逢春
 * @date 2022-06-19
 */
@Controller
@RequestMapping("/system/Company")
public class CoTestCompanyController extends BaseController
{
    private String prefix = "system/Company";

    @Autowired
    private ICoTestCompanyService coTestCompanyService;

    @RequiresPermissions("system:Company:view")
    @GetMapping()
    public String Company()
    {
        return prefix + "/Company";
    }

    /**
     * 查询公司管理列表
     */
    @RequiresPermissions("system:Company:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CoTestCompany coTestCompany)
    {
        startPage();
        List<CoTestCompany> list = coTestCompanyService.selectCoTestCompanyList(coTestCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司管理列表
     */
    @RequiresPermissions("system:Company:export")
    @Log(title = "公司管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CoTestCompany coTestCompany)
    {
        List<CoTestCompany> list = coTestCompanyService.selectCoTestCompanyList(coTestCompany);
        ExcelUtil<CoTestCompany> util = new ExcelUtil<CoTestCompany>(CoTestCompany.class);
        return util.exportExcel(list, "公司管理数据");
    }

    /**
     * 新增公司管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司管理
     */
    @RequiresPermissions("system:Company:add")
    @Log(title = "公司管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CoTestCompany coTestCompany)
    {
        return toAjax(coTestCompanyService.insertCoTestCompany(coTestCompany));
    }

    /**
     * 修改公司管理
     */
    @RequiresPermissions("system:Company:edit")
    @GetMapping("/edit/{coId}")
    public String edit(@PathVariable("coId") Long coId, ModelMap mmap)
    {
        CoTestCompany coTestCompany = coTestCompanyService.selectCoTestCompanyByCoId(coId);
        mmap.put("coTestCompany", coTestCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司管理
     */
    @RequiresPermissions("system:Company:edit")
    @Log(title = "公司管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CoTestCompany coTestCompany)
    {
        return toAjax(coTestCompanyService.updateCoTestCompany(coTestCompany));
    }

    /**
     * 删除公司管理
     */
    @RequiresPermissions("system:Company:remove")
    @Log(title = "公司管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(coTestCompanyService.deleteCoTestCompanyByCoIds(ids));
    }
}
